/**
 * May 7, 2014 9:14:38 AM
 */
package elitech.vietnam.copyweatherfashion.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import elitech.vietnam.copyweatherfashion.R;

/**
 * @author Cong
 *
 */
public class ButtonLike extends RelativeLayout {
	
	TextView mText;
	ImageView mImage;
	
	AttributeSet attrs;
	int type = 0;
	int[] resId;

	public ButtonLike(Context context) {
		super(context);
	}

	public ButtonLike(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.attrs = attrs;
	}

	public ButtonLike(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.attrs = attrs;
	}

	private void setUp(AttributeSet attrs) {
		mImage = (ImageView) findViewById(R.id.like_imgBackground);
		mText = (TextView) findViewById(R.id.like_txtText);
		
		if (attrs != null) {
			TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ButtonLike);
			type = typedArray.getResourceId(R.styleable.ButtonLike_type, 0);
			typedArray.recycle();
		}

		resId = new int[] {R.drawable.heart_like, R.drawable.heart_liked};
		if (type == 1)
			resId = new int[] {R.drawable.heart1_like, R.drawable.heart1_liked};
		
		mImage.setImageResource(resId[0]);
	}
	
	@Override
	protected void onFinishInflate() {
		super.onFinishInflate();
		setUp(attrs);
	}
	
	public void setData(boolean liked, int likes) {
		mText.setText(likes + "");
		mImage.setImageResource((liked) ? resId[1] : resId[0]);
	}
}
